package com.syuswe.qimo_02.controller;

import com.syuswe.qimo_02.mapper.EmpMapper;
import com.syuswe.qimo_02.pojo.Emp;
import com.syuswe.qimo_02.pojo.PageBean;
import com.syuswe.qimo_02.pojo.Result;
import com.syuswe.qimo_02.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author n7c.swe
 * {@code @date} 2024-05
 */
@RestController
@RequestMapping("/emps")
@Slf4j
public class EmpController {

    @Autowired
    private EmpService empService;
    @Autowired
    private EmpMapper empMapper;
//    private final EmpMapper empMapper;
//    @Autowired
//    public EmpController(EmpMapper empMapper){
//        this.empMapper=empMapper;
//    }
    @GetMapping
    public Result page(@RequestParam(defaultValue = "1") Integer page, //  @RequestParam(defaultValue = "1")设置默认1
                       @RequestParam(defaultValue = "10") Integer pageSize) {
        log.info("分页查询 参数:{},{}", page, pageSize);
        PageBean pageBean = empService.page(page, pageSize); // PageBean 作封装类
        return Result.success(pageBean);
    }

    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable List<Integer> ids) {
        log.info("批量删除操作,ids:{}", ids);
        empMapper.deleteBatchIds(ids);
        return Result.success();
    }

    // 新增员工
    @PostMapping
    public Result insertEmp(@RequestBody Emp emp) {
        log.info("新增员工,emp:{}", emp);
        empService.insertEmp(emp);
        return Result.success();
    }


}
